package com.mcptt.config.ue.initial.sub.sub;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;

public class AppServerInfo {
	public static final String Name = "App-Server-Info";

	private static final String Name_Gms = "gms";
	private static final String Name_Cms = "cms";
	private static final String Name_Kms = "kms";
	private static final String Name_Idms = "idms";
	private static final String Name_HttpProxy = "http-proxy";

	private static final String Name_Sbc = "sbc";
	private static final String Name_Dns = "dns";
	private static final String Name_IdmsAuthEndpoint = "idms-auth-endpoint";
	private static final String Name_IdmsLoginEndpoint = "idms-login-endpoint";
	private static final String Name_IdmsTokenEndpoint = "idms-token-endpoint";

//	public final static String Url_Auth = "/realms/crsc/protocol/openid-connect/auth";
//	public final static String Url_Login ="/realms/crsc/login-actions/authenticate";
//	public final static String Url_Token = "/realms/crsc/protocol/openid-connect/token";

	private String idmsAuthEndpoint = "/as/authorization.oauth2";
	private String idmsLoginEndpoint = "/as/digest/login";
	private String idmsTokenEndpoint = "/as/token.oauth2";
	private String gms = null;
	private String cms = null;
	private String kms = null;
//	private String idms = null;
	private String httpProxy = null;

	private String sbc = null;
	private String dns = null;

	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
//			Log.debug(this.getClass(), "name = " + name);
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(Name_Gms))
			{
				gms = subElem.getText();
			}
			else if(name.equals(Name_Cms))
			{
				cms = subElem.getText();
			}
			else if(name.equals(Name_Kms))
			{
				kms = subElem.getText();
			}
//			else if(name.equals(Name_Idms))
//			{
//				idms = subElem.getText();
//			}
			else if(name.equals(Name_Sbc))
			{
				sbc = subElem.getText();
			}
			else if(name.equals(Name_Dns))
			{
				dns = subElem.getText();
			}
			else if(name.equals(Name_HttpProxy))
			{
				httpProxy = subElem.getText();
			}
			else if(name.equals(Name_IdmsAuthEndpoint))
			{
				idmsAuthEndpoint = subElem.getText();
			}
			else if(name.equals(Name_IdmsLoginEndpoint))
			{
				idmsLoginEndpoint = subElem.getText();
			}
			else if(name.equals(Name_IdmsTokenEndpoint))
			{
				idmsTokenEndpoint = subElem.getText();
			}

		}  
	}
	
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Name).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_Gms).append(">");
		strBuf.append(gms);
		strBuf.append("</").append(Name_Gms).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_Cms).append(">");
		strBuf.append(cms);
		strBuf.append("</").append(Name_Cms).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_Kms).append(">");
		strBuf.append(kms);
		strBuf.append("</").append(Name_Kms).append(">").append("\r\n");

//		strBuf.append("    ").append("<").append(Name_Idms).append(">");
//		strBuf.append(idms);
//		strBuf.append("</").append(Name_Idms).append(">").append("\r\n");

		strBuf.append("    ").append("<").append(Name_HttpProxy).append(">");
		strBuf.append(httpProxy);
		strBuf.append("</").append(Name_HttpProxy).append(">").append("\r\n");

		strBuf.append("    ").append("<").append(Name_Sbc).append(">");
		strBuf.append(sbc);
		strBuf.append("</").append(Name_Sbc).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_Dns).append(">");
		strBuf.append(dns);
		strBuf.append("</").append(Name_Dns).append(">").append("\r\n");

		strBuf.append("    ").append("<").append(Name_IdmsAuthEndpoint).append(">");
		strBuf.append(idmsAuthEndpoint);
		strBuf.append("</").append(Name_IdmsAuthEndpoint).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_IdmsLoginEndpoint).append(">");
		strBuf.append(idmsLoginEndpoint);
		strBuf.append("</").append(Name_IdmsLoginEndpoint).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_IdmsTokenEndpoint).append(">");
		strBuf.append(idmsTokenEndpoint);
		strBuf.append("</").append(Name_IdmsTokenEndpoint).append(">").append("\r\n");
		strBuf.append("</").append(Name).append(">").append("\r\n");
		return strBuf.toString();
	}

	public String getIdmsAuthEndpoint() {
		return idmsAuthEndpoint;
	}

	public String getIdmsLoginEndpoint() {
		return idmsLoginEndpoint;
	}

	public String getIdmsTokenEndpoint() {
		return idmsTokenEndpoint;
	}

	public String getGms()
	{
	    return gms;
	}

	public String getCms()
	{
	    return cms;
	}

	public String getKms()
	{
	    return kms;
	}

//	public String getIdms() {
//		return idms;
//	}

	public String getHttpProxy() {
		return httpProxy;
	}

	public String getSbc() {
		return sbc;
	}
	public String getDns() {
		return dns;
	}
}
